<?php

$hasError = isset($_SESSION['has_error']) ? $_SESSION['has_error'] : false;
$inputBag = isset($_SESSION['input_bag']) ? $_SESSION['input_bag'] : ['username' => ''];
$errorBag = isset($_SESSION['error_bag']) ? $_SESSION['error_bag'] : ['username' => '','password' => '','code'=>''];

// 销毁session中的错误数据包 （错误数据包是一次性的）
if (isset($_SESSION['has_error']) && isset($_SESSION['input_bag']) && isset($_SESSION['error_bag'])) {
   unset($_SESSION['has_error']);
   unset($_SESSION['input_bag']);
   unset($_SESSION['error_bag']);
}
?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>留言板-登陆</title>
  <link rel="stylesheet" type="text/css" href="<?php echo assets('css/style.css') ?>">
</head>
<body>
  <div>
  	<form method="post" action="<?php echo url('signin_action') ?>">
  	  <div class="row">
  	  	<div class="input">
  	  	  <label>用户名</label>
  	  	  <input type="text" name="username" placeholder="请输入用户名" value="<?=$inputBag['username']?>">
  	  	</div>
        <div class="error">
          <?php if ($hasError) echo $errorBag['username'] ?>
        </div>
  	  	<div class="input">
  	  	  <label>密码</label>
  	  	  <input type="password" name="password" placeholder="请输入密码">
  	  	</div>
        <div class="error">
          <?php if ($hasError) echo $errorBag['password'] ?>
        </div>
        <div class="input">
          <label>验证码</label>
          <input class="code" type="text" name="code" placeholder="请输入验证码">
        </div>
        <div style="float: left;">
  	  	  <input type="checkbox" name="remember-me" id="remember-me" value="1">
  	  	  <label for="remember-me">记住我</label>
  	  	</div>
        <div class="error">
          <?php if ($hasError) echo $errorBag['code'] ?>
        </div>
        <div class="code">
          <a href="<?php echo url('signin') ?>"><img src="<?php echo assets('img/picture.php') ?>" align="center"></a>
        </div>
  	  	<div>
  	  	  <input class="button" type="submit" name="sign" value="登陆">
  	  	</div>
        <div>还没有账号？现在<a href="<?php echo url('register') ?>">注册</a></div>
  	  </div>
  	</form>
  </div>
</body>
</html>